/**
 *
 */
package com.aiou.security.validate.code;

import com.aiou.security.properties.SecurityProperties;
import com.aiou.security.validate.code.image.ImageCodeProcessor;
import com.aiou.security.validate.code.image.ImageValidateCodeGenerator;
import com.aiou.security.validate.code.sms.DefaultSmsCodeSender;
import com.aiou.security.validate.code.sms.SmsCodeProcessor;
import com.aiou.security.validate.code.sms.SmsCodeSender;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author zyb
 */
@Configuration
public class ValidateCodeBeanConfig {

    @Autowired
    private SecurityProperties securityProperties;

    @Bean
    @ConditionalOnMissingBean(name = "imageCodeGenerator")
    public ValidateCodeGenerator imageCodeGenerator() {
        ImageValidateCodeGenerator codeGenerator = new ImageValidateCodeGenerator();
        codeGenerator.setSecurityProperties(securityProperties);
        return codeGenerator;
    }


    @Bean
    @ConditionalOnMissingBean(SmsCodeSender.class)
    public SmsCodeSender smsCodeSender() {
        return new DefaultSmsCodeSender();
    }

    @Bean
    @ConditionalOnMissingBean(name = "smsValidateCodeProcessor")
    public ValidateCodeProcessor smsValidateCodeProcessor(SmsCodeSender smsCodeSender) {
        return new SmsCodeProcessor(smsCodeSender);
    }

    @Bean
    @ConditionalOnMissingBean(name = "imageValidateCodeProcessor")
    public ValidateCodeProcessor imageValidateCodeProcessor() {
        return new ImageCodeProcessor();
    }

}
